package cn.itheima.server_request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//1.获取请求中的三个路径访问IP获取指定的头信息Referer,User-Agent，并打印
    @WebServlet("/ServletTest1")
    public class ServletTest1 extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //获取三个路径
            System.out.println(request.getContextPath());
            System.out.println(request.getServletPath());
            System.out.println(request.getRequestURI());

            //获取访问者ip地址
            System.out.println(request.getRemoteAddr());

            //获取头信息
            System.out.println(request.getHeader("Host"));
            System.out.println(request.getHeader("User-Agent"));
        }

        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    }
